import axios from "axios";

/**
 * 获取经纬度根据地址
 * @param address
 */
export async function getLatitudeAndLongitudeByaddr(address: string) {
    const url = 'https://qryloct.market.alicloudapi.com/lundear/qryaddr';
    address = encodeURIComponent(address);
    const appCode = 'b75b012b5724490cb8321d1f36310a86';
    const config = {
        headers: {
            'Authorization': `APPCODE ${appCode}`
        },
        params: {
            address
        },
        validateStatus: null
    };
    try {
        const response = await axios.get(url, config);
        // console.log(`状态码: ${response.status}`);
        // console.log(`响应头: ${JSON.stringify(response.headers)}`);
        // console.log(`响应体: ${JSON.stringify(response.data)}`);
        return response.data; // 返回响应体数据
    } catch (error) {
        console.error(`请求经纬度接口异常: ${error}`);
        throw error;
    }
}